package com.songcha.library_common.util

import android.view.View
import android.view.ViewGroup
import androidx.core.view.setMargins
import androidx.core.view.setPadding
import com.songcha.library_common.util.AlgorithmUtil
import com.songcha.library_common.util.ScreenUtil

class StyleUtil {
    companion object{
        fun setMargin(lp:ViewGroup.MarginLayoutParams, margins: FloatArray){
            val format:FloatArray=AlgorithmUtil.formatStyleFloatArray(margins)

            for( i in format.indices){
                format[i]= ScreenUtil.dp2px(format[i])
            }



            lp.setMargins(format[0].toInt(),format[1].toInt(),format[2].toInt(),format[3].toInt())
        }

        fun setMargin(lp:ViewGroup.MarginLayoutParams, margin: Float){
            lp.setMargins(ScreenUtil.dp2px(margin).toInt())
        }

        fun setPadding(view: View, paddings: FloatArray){
            val format:FloatArray= AlgorithmUtil.formatStyleFloatArray(paddings)

            for( i in format.indices){
                format[i]=ScreenUtil.dp2px(format[i])
            }

            view.setPadding(format[0].toInt(),format[1].toInt(),format[2].toInt(),format[3].toInt())
        }

        fun setPadding(view: View, padding: Float){
            view.setPadding(ScreenUtil.dp2px(padding).toInt())
        }

        fun setWidth(lp:ViewGroup.LayoutParams, width: Float){
            lp.width=(ScreenUtil.dp2px(width).toInt())
        }

        fun setHeight(lp:ViewGroup.LayoutParams, height: Float){
            lp.height=(ScreenUtil.dp2px(height).toInt())
        }

    }



}